<template>
  <div class="traceInfo">
    <ul class="query">
      <li class="query-option">
        <span>关键词：</span>
        <el-input size="medium" v-model="queryData.goodsId" placeholder="商品ID"></el-input>
      </li>
      <li class="query-option">
        <span>下单日期：</span>
        <el-date-picker type="datetimerange" v-model="date" @change="changeDate" value-format="yyyy-MM-dd HH:mm:ss" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期" size="medium">
        </el-date-picker>
      </li>
      <li class="query-option">
        <span>酒的状态：</span>
        <el-select size="medium" v-model="queryData.status">
          <el-option value="" label="全部"></el-option>
          <el-option :value="0" label="可销售"></el-option>
          <el-option :value="1" label="冻结"></el-option>
          <el-option :value="2" label="出库"></el-option>
          <el-option :value="3" label="未存库"></el-option>
          <el-option :value="4" label="窖藏中"></el-option>
          <el-option :value="5" label="已自提"></el-option>
          <el-option :value="6" label="酒窖已转出"></el-option>
        </el-select>
      </li>
      <li class="query-option">
        <el-button size="medium" type="primary" @click="handleCurrentChange(1)">查询</el-button>
      </li>
    </ul>
    <div class="wrapper">
      <el-table class="table" :data="tableData" stripe highlight-current-row border>
        <el-table-column align="center" prop="goods_id" label="商品ID">
        </el-table-column>
        <el-table-column align="center" prop="order_no" label="订单号">
        </el-table-column>
        <el-table-column align="center" prop="create_time" label="下单时间">
        </el-table-column>
        <el-table-column align="center" prop="goods_name" label="商品名称">
        </el-table-column>
        <el-table-column align="center" prop="category" label="商品类别">
          <template slot-scope="scope">
            <span>{{scope.row.goods_kind_first}}/{{scope.row.goods_kind_second}}</span>
          </template>
        </el-table-column>
        <el-table-column align="center" prop="goodsStatus" label="酒的状态">
        </el-table-column>
        <el-table-column align="center" prop="operation" label="操作">
          <template slot-scope="scope">
            <span class="view-btn" @click="$router.push({path:'/traceDetail',query:{id:scope.row.goods_id}})">查看详情</span>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination v-show='page.total>page.pageSize' background layout="total,prev, pager, next,jumper" :page-size="page.pageSize" :total="page.total" :current-page="page.current" @current-change="handleCurrentChange">
      </el-pagination>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      date: [],
      queryData: {
        status: '',
        startTime: '',
        endTime: '',
        goodsId: ''
      },
      tableData: [],
      page: {
        pageSize: 10,
        current: 1,
        total: 0
      }
    };
  },
  mounted() {
    this.getTableData();
  },
  methods: {
    async getTableData() {
      let { data } = await this.$post({
        api: '/show/source/manage',
        data: {
          current: this.page.current,
          pageSize: this.page.pageSize,
          startTime: this.queryData.startTime,
          endTime: this.queryData.endTime,
          goodsId: this.queryData.goodsId,
          status: this.queryData.status
        }
      });
      if (data.code === 0) {
        this.tableData = data.data;
        this.page.total = data.rdPage.total;
      } else {
        this.$message({
          type: 'error',
          message: data.msg
        });
      }
    },
    handleCurrentChange(val) {
      this.page.current = val;
      this.getTableData();
    },
    changeDate(val) {
      if (val) {
        this.queryData.staartTime = val[0];
        this.queryData.endTime = val[1];
      } else {
        this.queryData.staartTime = '';
        this.queryData.endTime = '';
      }
    }
  }
};
</script>

<style lang="scss" scoped>
.query {
  overflow: hidden;
  padding: 15px 30px;
  border-bottom: 1px solid #eeeeee;
  &-option {
    float: left;
    margin-right: 40px;
    &:last-child {
      margin-right: 0;
    }
  }
  .el-input {
    width: 250px;
  }
}
.wrapper {
  padding: 0 15px;
  .view-btn {
    color: #0033ff;
    margin: 0 5px;
    cursor: pointer;
  }
}
</style>
